using MediatR;
using SumerCoreDevOps.Application.Workflows.Commands;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.Workflow;

namespace SumerCoreDevOps.Application.Workflows.Handlers;

/// <summary>
/// 创建工作流命令处理器
/// </summary>
public class CreateWorkflowCommandHandler : IRequestHandler<CreateWorkflowCommand, WorkflowDefinition>
{
    private readonly WorkflowDefinitionManager _definitionManager;

    public CreateWorkflowCommandHandler(WorkflowDefinitionManager definitionManager)
    {
        _definitionManager = definitionManager;
    }

    public async Task<WorkflowDefinition> Handle(CreateWorkflowCommand request, CancellationToken cancellationToken)
    {
        return await _definitionManager.CreateWorkflowAsync(
            request.Name,
            request.Description,
            request.Version,
            request.CreatedBy);
    }
}
